<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增服务商划拨、撤销机具申请信息')" />
    <th:block th:include="include :: jasny-bootstrap-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-pos-add">
            <input type="hidden" name="applyType" value="0">
            <div class="form-group">
                <label class="col-sm-3 control-label  is-required">服务商编号：</label>
                <div class="col-sm-8">
                    <input name="xagentNum" onclick="selectAgent()" readonly id="xagentNum" type="text" class="form-control" required>
                    <i class="fa fa-search" style="margin-top: -22px;margin-right:3px;float:right;"></i>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">服务商名称：</label>
                <div class="col-sm-8">
                    <input name="xagentName" class="form-control" id="xagentName" type="text" required readonly>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">申请数量：</label>
                <div class="col-sm-8">
                    <input name="applyNum" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">首付：</label>
                <div class="col-sm-8">
                    <input name="payMoney" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">欠款：</label>
                <div class="col-sm-8">
                    <input name="qmoney" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">机具类型：</label>
                <div class="col-sm-8">
                    <select name="posType" readonly  class="form-control" th:with="type=${@dict.getType('terminal_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                                th:selected = "${dict.dictValue eq agentApplyPos?.posType}" ></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">充值凭证：</label>
                <br/>
                <div class="fileinput fileinput-new" data-provides="fileinput">
                    <div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 200px; height: 150px;"></div>
                    <div>
                        <span class="btn btn-white btn-file"><span class="fileinput-new">充值凭证</span><span class="fileinput-exists">更改</span>
                            <input type="file" name="payPic"></span>
                        <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <script th:inline="javascript">
        var prefix = ctx + "terminal/pos"
        $("#form-pos-add").validate({
            focusCleanup: true
        });

        function selectAgent() {
            var url = prefix+"/selectAgentInfo";
            $.modal.open("选择服务商" , url, '700');
        }

        function submitHandler() {
            if ($.validate.form()) {
                var formData = new FormData();
                formData.append("payPic", $("[name='payPic']").get(0).files[0]);
                var xagentNum=$("[name='xagentNum']").val();
                formData.append("xagentNum",xagentNum);
                var xagentName=$("[name='xagentName']").val();
                formData.append("xagentName",xagentName);
                var applyNum=$("[name='applyNum']").val();
                formData.append("applyNum",applyNum);
                var qmoney=$("[name='qmoney']").val();
                formData.append("qmoney",qmoney);
                var payMoney=$("[name='payMoney']").val();
                formData.append("payMoney",payMoney);

                var posType=$("[name='posType']").val();
                formData.append("posType",posType);

                $.ajax({
                    url : prefix + "/add",
                    type: 'POST',
                    data: formData,
                    cache: false,
                    contentType: false,
                    processData: false,
                    beforeSend: function () {
                        $.modal.loading("正在处理中，请稍后...");
                        $.modal.disable();
                    },
                    success : function(result) {
                        if (result.code == web_status.SUCCESS) {
                            var parent = window.parent;
                            if (parent.table.options.type == table_type.bootstrapTable) {
                                $.modal.close();
                                parent.$.modal.msgSuccess(result.msg);
                                parent.$.table.refresh();
                            } else if (parent.table.options.type == table_type.bootstrapTreeTable) {
                                $.modal.close();
                                parent.$.modal.msgSuccess(result.msg);
                                parent.$.treeTable.refresh();
                            } else {
                                $.modal.msgReload("保存成功,正在刷新数据请稍后……", modal_status.SUCCESS);
                            }
                        } else if (result.code == web_status.WARNING) {
                            $.modal.alertWarning(result.msg)
                        }  else {
                            $.modal.alertError(result.msg);
                        }
                        $.modal.closeLoading();
                        $.modal.enable();
                        //$.modal.alertSuccess(data.msg)
                    },
                    error : function(result) {
                        $.modal.alertError(result.msg);
                    }
                });
            }
        }
    </script>
</body>
</html>